package com.cortex.papaya.search;

import java.util.List;

import org.carrot2.core.Document;

import com.cortex.papaya.utilities.MyLog;

import android.graphics.Bitmap;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

public class Link {
	private Document document;
	private Bitmap image;
	private Category category;
	private int index;
	private OnDataChangedListener onDataChangedListener;
	
	public Link(Document document) {
		this.document = document;
	}

	public Link(Document document,int index, Category category) {
		this.document = document;
		this.category = category;
		this.index = index;
	}

	public Document getDocument() {
		return document;
	}
	public String getName() {
		return document.getTitle();
	}
	public int getId() {
		return document.getId();
	}
	public String getSummaryUrl(){
		String summaryName = document.getContentUrl();
		String [] summeryNameArray = summaryName.split("/");
		// return summary url without  "http://www." and without  url after ".com"
		return summeryNameArray[2].substring(4);
	}
	public double getSocre() {
		return document.getScore();
	}

	public String getUrl() {
		// TODO Auto-generated method stub
		return document.getContentUrl();
	}
	public String getSummary(){
		return document.getSummary();
	}
	public Bitmap getImage() {
		return image;
	}
	public void setImage(Bitmap image) {
		this.image = image;
		if(onDataChangedListener != null){
			onDataChangedListener.dataChanged(this);
		}
	}
	public Category getCategory() {
		return category;
	}
	public void setCategory(Category category) {
		this.category = category;
		if(onDataChangedListener != null){
			onDataChangedListener.dataChanged(this);
		}
	}
	public int getIndex() {
		return index;
	}
	@Override
	public boolean equals(Object o) {
		if(this == o){
			return true;
		}
		if(o instanceof Link){
			Link document = (Link)o;
			if(getId() == document.getId()){
				return true;
			}
		}
		return false;
	}
	public void setOnDataChangedListener(
			OnDataChangedListener onDataChangedListener) {
		this.onDataChangedListener = onDataChangedListener;
	}
	public interface OnDataChangedListener{
		void dataChanged(Link document);
	}
	public String toString(){
		return "id=" + document.getId() + "\n" + 
				"name=" + document.getTitle() + "\n" + 
				"url=" + document.getContentUrl() + "\n" +
				"index=" + getIndex();
	}
}